#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;

int getHot(int housepos, vector<int>& heaters) {
    int left = 0;
    int right = heaters.size() - 1;
    while (left <= right) {
        int mid = left + right >> 1;
        if (heaters[mid] == housepos) return mid;
        if (heaters[mid] > housepos && heaters[mid - 1] <= housepos)
            return mid - 1;
        if (heaters[mid] > housepos) right = mid - 1;
        if (heaters[mid] < housepos && heaters[mid + 1] > housepos) return mid;
        if (heaters[mid] < housepos) left = mid+1;
    }
    return -1;
}

int findRadius(vector<int>& houses, vector<int>& heaters) {
    sort(heaters.begin(), heaters.end());
    int ans = -1;
    for (int i = 0; i < houses.size(); i++) {
        int m = getHot(houses[i], heaters);
        if(m == heaters.size() - 1) ans = max(ans, houses[i] - heaters[m]);
        else{
            ans = max(ans, min(houses[i] - heaters[m], heaters[m+1] - houses[i]));
        }
    }
    return ans;
}